package com.xiaoyun.controller;

import com.xiaoyun.constant.Const;
import com.xiaoyun.service.ItemsEsService;
import com.xiaoyun.utils.PagedGridResult;
import com.xiaoyun.utils.XYJSONResult;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Data
public class ItemsController {

    private final ItemsEsService itemsEsService;

    @GetMapping("/es/search")
    public XYJSONResult search(
             String keywords,
             String sort,
            @RequestParam(required = false, defaultValue = "1") Integer page,
            @RequestParam(required = false, defaultValue = Const.PAGE_SIZE) Integer pageSize) {

        page--;

        PagedGridResult grid = itemsEsService.searchItems(keywords, sort, page, pageSize);
        return XYJSONResult.ok(grid);
    }
}
